//
//  OrderTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/18.
//

#import "OrderTableViewCell.h"

@implementation OrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatView{
    self.backgroundColor=[UIColor clearColor];
    
    UIView *centerView=[UIView new];
    [self.contentView addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(10*_mainHeight);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];

    UIImageView *backImage=[UIImageView new];
    [centerView addSubview:backImage];
    [backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    [backImage layoutIfNeeded];
    backImage.image=[UIImage imageNamed:@"ordercell"];
    backImage.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    backImage.layer.shadowOffset = CGSizeMake(0,0);
    backImage.layer.shadowOpacity = 1;
    backImage.layer.shadowRadius = 4;
    
    UIImageView *xianView=[UIImageView new];
    [centerView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*31);
        make.right.mas_equalTo(-31*_mainWidth);
        make.height.mas_equalTo(2*_mainHeight);
        make.top.mas_equalTo(81.5*_mainHeight);
    }];
    xianView.image=[UIImage imageNamed:@"xinxifengexian"];
    
    UIView *topView=[UIView new];
    [centerView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(81*_mainHeight);
    }];
    
    UILabel *orderLabel=[UILabel new];
    [topView addSubview:orderLabel];
    [orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    [orderLabel layoutIfNeeded];
    orderLabel.text=@"订单号：KY12321325135215";
    orderLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    orderLabel.textColor=rgba(102,102,102,1);
    
    UIButton *copyBtn=[UIButton new];
    [topView addSubview:copyBtn];
    [copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(orderLabel.mas_right).mas_equalTo(24*_mainWidth);
        make.width.height.mas_equalTo(30*_mainWidth);
    }];
    [copyBtn setImage:[UIImage imageNamed:@"fuzhi"] forState:0];
    [copyBtn addTarget:self action:@selector(copyClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.typpeLabel=[UILabel new];
    [topView addSubview:self.typpeLabel];
    [self.typpeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
   
    UIImageView *imageView=[UIImageView new];
    [centerView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(14.5*_mainHeight);
        make.width.mas_equalTo(114*_mainWidth);
        make.height.mas_equalTo(78*_mainWidth);
    }];
    
    UILabel *stateLabel=[UILabel new];
    [centerView addSubview:stateLabel];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(11*_mainHeight);
    }];
    [stateLabel layoutIfNeeded];
    stateLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    
    
    UILabel *cityLabel=[UILabel new];
    [centerView addSubview:cityLabel];
    [cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(imageView.mas_left).mas_equalTo(-61*_mainWidth);
        make.bottom.mas_equalTo(imageView);
    }];
    [cityLabel layoutIfNeeded];
    cityLabel.text=@"杭州市";
    cityLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    cityLabel.textColor=rgba(51, 51, 51, 1);
    
    UILabel *nameLabel=[UILabel new];
    [centerView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(stateLabel);
        make.centerX.mas_equalTo(cityLabel);
    }];
    nameLabel.text=@"林杰伦";
    nameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    nameLabel.textColor=rgba(153,153,153,1);
    
    UILabel *cityLabel2=[UILabel new];
    [centerView addSubview:cityLabel2];
    [cityLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_right).mas_equalTo(61*_mainWidth);
        make.bottom.mas_equalTo(imageView);
    }];
    [cityLabel2 layoutIfNeeded];
    cityLabel2.text=@"上海市";
    cityLabel2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    cityLabel2.textColor=rgba(51, 51, 51, 1);
    
    UILabel *nameLabel2=[UILabel new];
    [centerView addSubview:nameLabel2];
    [nameLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(stateLabel);
        make.centerX.mas_equalTo(cityLabel2);
    }];
    nameLabel2.text=@"林杰伦";
    nameLabel2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    nameLabel2.textColor=rgba(153,153,153,1);

    UILabel *timeLabel=[UILabel new];
    [centerView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25*_mainWidth);
        make.bottom.mas_equalTo(-38*_mainHeight);
    }];
    timeLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    timeLabel.textColor=rgba(102,102,102,1);
   
    
    UIButton *submitBtn=[UIButton new];
    [centerView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-25*_mainWidth);
        make.centerY.mas_equalTo(timeLabel);
        make.width.mas_equalTo(_mainWidth*142);
        make.height.mas_equalTo(58*_mainHeight);
    }];
    submitBtn.layer.borderWidth=2*_mainWidth;
    submitBtn.layer.borderColor=rgba(250,100,0,1).CGColor;
    submitBtn.layer.masksToBounds=YES;
    submitBtn.layer.cornerRadius=29*_mainHeight;
    
    [submitBtn setTitleColor:rgba(250,100,0,1) forState:0];
    submitBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    
    submitBtn.hidden=YES;
    if (self.tag==0) {
        NSString *titleStr=[NSString stringWithFormat:@"签收码：%@",@"1234"];
        NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
        NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"签收码："]];//匹配得到的下标
        NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"%@",@"1234"]];//匹配得到的下标
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)] range:priceRange];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(51,51,51,1) range:priceRange];
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)] range:priceRange2];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(250,100,0,1) range:priceRange2];
        self.typpeLabel.attributedText=titleAttri;
        
        imageView.image=[UIImage imageNamed:@"lvsehuoche"];
        stateLabel.text=@"已完成";
        stateLabel.textColor=rgba(0,190,146,1);
        
        timeLabel.text=@"完成时间：2021-08-08";
        
        submitBtn.hidden=YES;
        
    }else if (self.tag==1) {
        self.typpeLabel.hidden=YES;
        
        imageView.image=[UIImage imageNamed:@"chengsedaba"];
        stateLabel.text=@"待签收";
        stateLabel.textColor=rgba(250,100,0,1);
        
        timeLabel.text=@"预计送达时间：2021-08-08 12:30";
        
        submitBtn.hidden=YES;
    }else if (self.tag==2) {
        self.timeTick=1800;
        NSString *typeStr=[NSString stringWithFormat:@"  %ld:%ld",self.timeTick/60,self.timeTick%60];
        NSMutableAttributedString *attri =  [[NSMutableAttributedString alloc] initWithString:typeStr];
        // 2.添加表情图片
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        // 表情图片
        attch.image = [UIImage imageNamed:@"shijian"];
            // 设置图片大小
        attch.bounds = CGRectMake(0, -2*_mainWidth, 24*_mainWidth, 24*_mainWidth);
        // 创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        [attri insertAttributedString:string atIndex:0];//插入某个位置

        self.typpeLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
        self.typpeLabel.attributedText=attri;
        self.typpeLabel.textColor=rgba(153,153,153,1);
        self.timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
        
        imageView.image=[UIImage imageNamed:@"chengsekongyun"];
        stateLabel.text=@"待付款";
        stateLabel.textColor=rgba(250,100,0,1);
        
        timeLabel.text=@"下单时间：2021-08-08 12:35";
        submitBtn.hidden=NO;
        [submitBtn setTitle:@"立即支付" forState:0];
    }else if (self.tag==3) {
        NSString *titleStr=[NSString stringWithFormat:@"签收码：%@",@"1234"];
        NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
        NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"签收码："]];//匹配得到的下标
        NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"%@",@"1234"]];//匹配得到的下标
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)] range:priceRange];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(51,51,51,1) range:priceRange];
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)] range:priceRange2];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(250,100,0,1) range:priceRange2];
        self.typpeLabel.attributedText=titleAttri;
        
        imageView.image=[UIImage imageNamed:@"chengsedaba"];
        stateLabel.text=@"待揽件";
        stateLabel.textColor=rgba(250,100,0,1);
        
        timeLabel.text=@"预约上门时间：2021-08-08 12:30～1:00";
        
    }else if (self.tag==4) {
        self.typpeLabel.hidden=YES;
        
        imageView.image=[UIImage imageNamed:@"huisekongyun"];
        stateLabel.text=@"已取消";
        stateLabel.textColor=rgba(51,51,51,1);
        
        timeLabel.text=@"预计送达时间：2021-08-08";
        submitBtn.hidden=YES;
    }else if (self.tag==5) {
        self.typpeLabel.hidden=YES;
        
        imageView.image=[UIImage imageNamed:@"huisehuoche"];
        stateLabel.text=@"退款中";
        stateLabel.textColor=rgba(250,100,0,1);
        
        timeLabel.text=@"退款申请时间：2021-08-08 12:30";
        submitBtn.hidden=YES;
    }else if (self.tag==6) {
        self.typpeLabel.hidden=YES;
        
        imageView.image=[UIImage imageNamed:@"huisehuoche"];
        stateLabel.text=@"已退款";
        stateLabel.textColor=rgba(38,129,215,1);
        
        timeLabel.text=@"退款到账时间：2021-08-08 12:30";
        submitBtn.hidden=YES;
    }
    
    //    [submitBtn addTarget:self action:@selector(selectPushToCashier) forControlEvents:UIControlEventTouchUpInside];
}
-(void)timeFireMethod
{
    if (_timeTick==0) {
        
        [_timer invalidate];
        return;
    }
    _timeTick--;
    
    NSString *typeStr=[NSString stringWithFormat:@"  %ld:%ld",self.timeTick/60,self.timeTick%60];
    
    NSMutableAttributedString *attri =  [[NSMutableAttributedString alloc] initWithString:typeStr];
    // 2.添加表情图片
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    // 表情图片
    attch.image = [UIImage imageNamed:@"shijian"];
        // 设置图片大小
    attch.bounds = CGRectMake(0, -2*_mainWidth, 24*_mainWidth, 24*_mainWidth);
    // 创建带有图片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    [attri insertAttributedString:string atIndex:0];//插入某个位置
    self.typpeLabel.attributedText=attri;
    
}

- (void)copyClick {
    UIPasteboard *pab = [UIPasteboard generalPasteboard];
    pab.string = @"12345";

}

@end
